import request from '@/utils/request'
import defaultSettings from '@/settings'

/**
 * 待部署列表
 * @param {*} query
 */
export function fetchUndeployList(query) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/modeler/undeployList',
    method: 'post',
    data: query
  })
}

/**
 * 已部署列表
 * @param {*} query
 */
export function fetchDeployList(query) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/modeler/deployList',
    method: 'post',
    data: query
  })
}
/**
 * 部署流程
 * @param {*} modelId
 * @param {*} typeId 流程类型
 */
export function deployById(modelId, typeId) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/modeler/deployById?id=' + modelId + '&flowModelTypeId=' + typeId,
    method: 'get'
  })
}

/**
 * 部署流程
 * @param {*} modelKey
 * @param {*} typeId 流程类型
 */
export function deployByKey(modelKey, typeId) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/modeler/deployByKey?modelKey=' + modelKey + '&flowModelTypeId=' + typeId,
    method: 'get'
  })
}

//发起流程列表
export function getSelfModelDeployList(query) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/user/getSelfModelDeployList',
    method: 'post',
    data: query
  })
}

/**
 * 撤销流程
 * @param {*} ids
 */
export function undeploy(ids) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/modeler/undeploy?ids=' + ids,
    method: 'get'
  })
}

/**
 * 删除未部署流程
 * @param {*} ids
 */
export function deleteModelById(id) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/modeler/deleteModelById?id=' + id,
    method: 'get'
  })
}

/**
 * 预览流程图
 * @param {*} modelKey
 */
export function diagram(modelKey,processInstanceId) {
  if(!processInstanceId){
    processInstanceId = ''
  }
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/modeler/diagram?modelKey=' + modelKey +'&processInstanceId='+processInstanceId,
    method: 'get'
  })
}

/**
 * 绑定用户
 * @param {*} deployId
 * @param {*} userId
 */
export function binding(modelKey, userIds) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/user/binding?modelKey=' + modelKey + '&userIds=' + userIds,
    method: 'get'
  })
}

export function getUserIdByBindingModel(modelKey, category) {
  return request({
    url: defaultSettings.serviceUrl.moon_fast + '/flowable/user/getUserIdByBindingModel?modelKey=' + modelKey + '&category=' + category,
    method: 'get'
  })
}

